PIC24F
PWRMgmt Module Library Help


Table Of Contents

1     Library Features. 3

2     Using Library Functions in Your Code. 3

3     Functions. 3

3.1        PwrMgnt_ResetSource. 3

3.2        PwrMgnt_WakeupSource. 3

3.3        PwrMgnt_OscSel 3

3.4        PwrMgnt_ClkDiv_Sel 4

4     Macros. 4

4.1        mPWRMGNT_RecoverOnInterrupt (polarity) 4

4.2        mPWRMGNT_PeriClkRatioSelect(ratio) 4

4.3        mPWRMGNT_FRCPostScalerSelect(postscaler) 4

4.4        mPWRMGNT_FRCOscTuningBits(bits) 5

4.5        mPWRMGNT_GetClkFailDetectBit() 5

4.6        mPWRMGNT_GotoSleepMode() 5

4.7        mPWRMGNT_GotoIdleMode() 5

4.8        mPWRMGNT_Clear_PORbit() 6

4.9        mPWRMGNT_GotoIdleMode() 6

4.10       mPWRMGNT_Clear_BORbit() 6

4.11       mPWRMGNT_Clear_WDTObit() 6

4.12       mPWRMGNT_Clear_SWRbit() 6

4.13       mPWRMGNT_Clear_EXTRbit() 7

4.14       mPWRMGNT_Clear_CMbit() 7

4.15       mPWRMGNT_Clear_IOPUWRbit() 7

4.16       mPWRMGNT_Clear_TRAPRbit() 7

4.17       mPWRMGNT_GetPLL_LockStatus() 7

 


1          Library Features

 

This peripheral library module:

 

·         Implements Power Management features of the device.

·         Provides functions to switch between operating frequency.

·         Provides macros to detect the reset source and to enter the device into IDLE/Sleep modes.

 

2          Using Library Functions in Your Code

Library routine parameters can be constructed using either AND based mask or AND_OR based mask setting. For more information on these masks, see 16-bit Peripheral Libraries.

 

Example of Use ( AND_OR mask )

 

Function Call:

 

PwrMgnt_ClkDiv_Sel(INTR_CLEAR_DOZEN_BIT | PERI_CLK_RATIO_16 |

                   PERI_CLK_RATIO_SET_1 | FRC_POSTSCALER_SEL_8);

 

3          Functions

3.1         PwrMgnt_ResetSource

 

Function Prototype

RESET_SOURCE PwrMgnt_ResetSource(void);

Include

PwrMgnt.h

Description

This function returns the source of reset.

Arguments

None

Return Value

RESET_SOURCE - Enum value representing the source of the reset. Enum is defined in PwrMgnt.h.

Remarks:

None

Source File:

PwrMgnt_ResetSource.c

3.2         PwrMgnt_WakeupSource

 

Function Prototype

WAKEUP_SOURCE PwrMgnt_WakeupSource(void);

Include

PwrMgnt.h

Description

This function returns the source of wakeup.

Arguments

None

Return Value

WAKEUP_SOURCE - Enum value representing the source of the wakeup. Enum is defined in PwrMgnt.h.

Remarks:

None

Source File:

PwrMgnt_WakeupSource.c

3.3         PwrMgnt_OscSel

 

Function Prototype

BOOL PwrMgnt_OscSel(UINT16 new_oscsel)

Include

PwrMgnt.h

Description

This function should be used to select the appropriate oscillator.

Arguments

new_oscsel - This parameter is the value of the new oscillator to be selected.

Return Value

BOOL -

   TRUE : If successfully changed new  oscillator select bits.

   FALSE: If 'FCKSM1 = 1' or new oscillator value is same as old oscillator value or PLL is not locked.

Remarks:

Global interrupts are disabled while the oscillator is being switched.

Source File:

PwrMgnt_OscSel.c

3.4         PwrMgnt_ClkDiv_Sel

 

Function Prototype

void PwrMgnt_ClkDiv_Sel(UINT16 clk_div_config)

Include

PwrMgnt.h

Description

This function should be used to select the appropriate oscillator.

Arguments

clk_div_config - This parameter is the value of the CLKDIV register.

Return Value

None

Remarks:

None

Source File:

PwrMgnt_ClkDiv_Sel.c

 

4          Macros

4.1         mPWRMGNT_RecoverOnInterrupt (polarity)

 

Macro

mPWRMGNT_RecoverOnInterrupt (polarity)

Include

PwrMgnt.h

Description

Sets ROI bitfield polarity.

Arguments

polarity -

1 = Interrupts clear the DOZEN bit and reset the CPU peripheral clock ratio to 1:1.

0 = Interrupts have no effect on the DOZEN bit.

Remarks

None

4.2         mPWRMGNT_PeriClkRatioSelect(ratio)

 

Macro

mPWRMGNT_PeriClkRatioSelect(ratio)

Include

PwrMgnt.h

Description

Selects Peripheral Clock Ratio Select bits in DOZE mode.

Arguments

ratio - n, where n=0 to 7.

DOZE2:DOZE0: CPU Peripheral Clock Ratio Select bits

   0b111 = 1:128

   0b110 = 1:64

   0b101 = 1:32

   0b100 = 1:16

   0b011 = 1:8

   0b010 = 1:4

   0b001 = 1:2

   0b000 = 1:1

Remarks

None

4.3         mPWRMGNT_FRCPostScalerSelect(postscaler)

 

Macro

mPWRMGNT_FRCPostScalerSelect(postscaler)

Include

PwrMgnt.h

Description

Selects Peripheral Clock Ratio Select bits.

Arguments

postscaler - n, where n=0 to 7.

RCDIV2:RCDIV0 : CPU Peripheral Clock Ratio Select bits

   0b111 = 31.25 kHz (divide by 256)

   0b110 = 125 kHz   (divide by 64)

   0b101 = 250 kHz   (divide by 32)

   0b100 = 500 kHz   (divide by 16)

   0b011 = 1 MHz     (divide by 8)

   0b010 = 2 MHz     (divide by 4)

   0b001 = 4 MHz     (divide by 2)

   0b000 = 8 MHz     (divide by 1)

Remarks

None

4.4         mPWRMGNT_FRCOscTuningBits(bits)

 

Macro

mPWRMGNT_FRCOscTuningBits(bits)

Include

PwrMgnt.h

Description

Selects FRC Osc Tuniing bits.

Arguments

bits - TUN5:TUN0: FRC Oscillator Tuning bits

0b011111 = Maximum frequency deviation

0b000001

0b000000 = Center frequency*

0b111111

0b100001

0b100000 = Minimum frequency deviation

 

* Oscillator is running at factory calibrated frequency.

Remarks

None

4.5         mPWRMGNT_GetClkFailDetectBit()

 

Macro

mPWRMGNT_GetClkFailDetectBit()

Include

PwrMgnt.h

Description

Returns:

   1 = FSCM has detected a clock failure

   0 = No clock failure has been detected

Arguments

None

Remarks

None

4.6         mPWRMGNT_GotoSleepMode()

 

Macro

mPWRMGNT_GotoSleepMode()

Include

PwrMgnt.h

Description

Enters device into SLEEP mode.

Arguments

None

Remarks

Device goes into sleep mode. Device will wake if any of the following conditions are satisfied:

- On any interrupt source that is individually enabled

- On any form of device Reset

- On a WDT time-out

4.7         mPWRMGNT_GotoIdleMode()

 

Macro

mPWRMGNT_GotoIdleMode()

Include

PwrMgnt.h

Description

Enters device into IDLE mode.

Arguments

None

Remarks

Device goes into idle mode. Device will wake if any of the following conditions are satisfied:

- On any interrupt source that is individually enabled

- On any form of device Reset

- On a WDT time-out

4.8         mPWRMGNT_Clear_PORbit()

 

Macro

mPWRMGNT_Clear_PORbit()

Include

PwrMgnt.h

Description

Clears the Power-On Reset bit.

Arguments

None

Remarks

This will not clear BOR bit.

4.9         mPWRMGNT_GotoIdleMode()

 

Macro

mPWRMGNT_GotoIdleMode()

Include

PwrMgnt.h

Description

Macro to enter device into IDLE mode.

Arguments

None

Remarks

Device goes into idle mode. Device will wake if any of the following conditions are satisfied:

- On any interrupt source that is individually enabled

- On any form of device Reset

- On a WDT time-out

4.10     mPWRMGNT_Clear_BORbit()

 

Macro

mPWRMGNT_Clear_BORbit()

Include

PwrMgnt.h

Description

Clears the Brown-Out Reset bit.

Arguments

None

Remarks

None

4.11     mPWRMGNT_Clear_WDTObit()

 

Macro

mPWRMGNT_Clear_WDTObit()

Include

PwrMgnt.h

Description

Clears the Watchdog Timer Reset bit.

Arguments

None

Remarks

None

4.12     mPWRMGNT_Clear_SWRbit()

 

Macro

mPWRMGNT_Clear_SWRbit()

Include

PwrMgnt.h

Description

Clears the Software Reset bit.

Arguments

None

Remarks

None

4.13     mPWRMGNT_Clear_EXTRbit()

 

Macro

mPWRMGNT_Clear_EXTRbit()

Include

PwrMgnt.h

Description

Clears the External Reset bit.

Arguments

None

Remarks

None

4.14     mPWRMGNT_Clear_CMbit()

 

Macro

mPWRMGNT_Clear_CMbit()

Include

PwrMgnt.h

Description

Clears the Configuration Word Mismatch Reset bit.

Arguments

None

Remarks

None

4.15     mPWRMGNT_Clear_IOPUWRbit()

 

Macro

mPWRMGNT_Clear_IOPUWRbit()

Include

PwrMgnt.h

Description

Clears Illegal Instruction Reset bit.

Arguments

None

Remarks

None

4.16     mPWRMGNT_Clear_TRAPRbit()

 

Macro

mPWRMGNT_Clear_TRAPRbit()

Include

PwrMgnt.h

Description

Clears trap Reset bit.

Arguments

None

Remarks

None

4.17     mPWRMGNT_GetPLL_LockStatus()

 

Macro

mPWRMGNT_GetPLL_LockStatus()

Include

PwrMgnt.h

Description

Returns:

1 = PLL module is in lock or PLL module start-up timer is satisfied.

0 = PLL module is out of lock, PLL start-up timer is running or PLL is disabled.

Arguments

None

Remarks

None